<template>
    <div class="cont mb-4">
        <CustomQuery @submit="changeQuery" :form-columns="queryList"></CustomQuery>
    </div>
    <div class="cont">
        <CustomTable selection :columns="columns" :data-source="data">
            <template #column-head="{ record }">
                <div class="flex-center">
                    <img class="w-10 h-10 rounded-full" :src="record.head" alt="用户头像">
                </div>
            </template>
            <template #column-state="{ column }">
                <a-tag color="green">活跃</a-tag>
            </template>
            <template #column-action="{ column }">
                <a-button type="primary" :icon="h(EditOutlined)">编辑</a-button>
            </template>
        </CustomTable>
    </div>
</template>

<script setup lang="ts">
import { PlusOutlined, EditOutlined } from '@ant-design/icons-vue';
import { h } from 'vue'

import CustomTable from '@/components/customTable/CustomTable.vue';
import CustomQuery from '@/components/customQuery/CustomQuery.vue';
import { CustomQueryColumns, CustomQueryValue } from '@/components/customQuery/types';
import { CustomTableColumns, CUstomTableData } from '@/components/customTable/types';

const queryList = reactive<CustomQueryColumns[]>([
    { label: '用户编号', key: 'code', type: 'input' },
    { label: '昵称', key: 'name', type: 'input' },
    { label: '手机号', key: 'phone', type: 'input' },
    {
        label: '状态', key: 'state', type: 'select', options: [
            { label: '状态: 全部', value: '1' },
            { label: '状态: 启用', value: '2' },
            { label: '状态: 禁用', value: '3' },
        ],value:'1'
    },
])

const changeQuery = (queryState: CustomQueryValue) => {
    alert('查询结果为' + JSON.stringify(queryState))
}

const data = ref<CUstomTableData[]>([])
const columns = reactive<CustomTableColumns[]>([
    {
        title: "编号",
        dataIndex: "code",
        key: "code",
    },
    {
        title: "头像",
        dataIndex: "head",
        key: "head",
        bodyCell: 'head'
    },
    {
        title: "昵称",
        dataIndex: "name",
        key: "name",
    },
    {
        title: "手机号",
        dataIndex: "phone",
        key: "phone",
    },
    {
        title: "地区",
        dataIndex: "location",
        key: "location",
    },
    {
        title: "状态",
        dataIndex: "state",
        key: "state",
        bodyCell: 'state'
    },
    {
        title: "时间",
        dataIndex: "time",
        key: "time",
    },
    {
        flag: 'ACTION'
    },
]);


onMounted(() => {
    for (let i = 0; i < 100; i++) {
        data.value.push(
            { code: '01', name: '已经很棒了', phone: '13236774266', location: '沈阳市浑南区', state: '1', time: '2024-08-16', head: 'https://ts1.cn.mm.bing.net/th?id=OIP-C._YFRagbOM8FbGUSUJy-m6QAAAA&w=250&h=250&c=8&rs=1&qlt=90&o=6&dpr=1.3&pid=3.1&rm=2' },
        )
    }
})
</script>

<style scoped></style>